package org.mikeliu.exp4.exp7;

import java.io.InterruptedIOException;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Objects;
import java.util.Scanner;

class Student implements Comparable<Student>
{
	private String name;
	private int id;
	private int score=0;
	private int number=0;
	@Override
	public int compareTo(Student o)
	{
		if(o.getAverage()>this.getAverage())
		{
			return 1;
		}
		else if(o.getAverage()<this.getAverage())
		{
			return -1;
		}
		else 
		{
			if(o.id>this.id)
			{
				return -1;
			}
			else if(o.id<this.id)
			{
				return 1;
			}
		}
		return 0;
	}
	public String getName() 
	{
		return name;
	}
	public void setName(String name) 
	{
		this.name = name;
	}
	public int getId() 
	{
		return id;
	}
	public void setId(int id) 
	{
		this.id = id;
	}
	public void addScore(int score)
	{
		this.score+=score;
		number++;
	}
	public double getAverage() 
	{
		return score/(double)number;
	}
	public Student(String name, int id) 
	{
		super();
		this.name = name;
		this.id = id;
		//this.average = average;
	}
	@Override
	public int hashCode() 
	{
		return Objects.hash(id, name);
	}
	@Override
	public boolean equals(Object obj) 
	{
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Student other = (Student) obj;
		return id == other.id && Objects.equals(name, other.name);
	}
	
}

public class Main 
{
	public static void main(String[] args)
	{
		List<Student> stuList=new ArrayList<Student>();
		Scanner scanner=new Scanner(System.in);
		String valueString="";
		valueString=scanner.nextLine();
		while(!valueString.equals("exit"))
		{
			
			String[] splitedStrings=valueString.split(",");
			Student student=new Student(splitedStrings[0],Integer.parseInt(splitedStrings[1]));
			if(stuList.contains(student))
			{
				stuList.get(stuList.indexOf(student)).addScore(Integer.parseInt(splitedStrings[3]));
			}
			else 
			{
				student.addScore(Integer.parseInt(splitedStrings[3]));
				stuList.add(student);
			}
			valueString=scanner.nextLine();
		}
		stuList.sort(new Comparator<Student>() 
		{
			@Override
			public int compare(Student o1, Student o2) 
			{
				return o1.compareTo(o2);
			}
		});
		for(int i=0;i<stuList.size();i++)
		{
			System.out.println("No"+(i+1)+":"+stuList.get(i).getId()+","+stuList.get(i).getName());
		}
		scanner.close();
	}
}
